/*
 * @Descripttion: $0
 * @version: 
 * @Author: linPing
 * @Date: 2019-10-29 01:26:12
 * @LastEditTime: 2019-11-04 17:08:55
 */
import React, {Component} from 'react';
// import {Provider} from 'react-redux';
import AppNavigator from './navigator/AppNavigators';
// import store from './store'
// import analytics from '@react-native-firebase/analytics';
import {Provider} from 'mobx-react'
import store from './Mobx'

type Props = {};
global.navigation = null

// gets the current screen from navigation state
function getActiveRouteName(navigationState) {
    if (!navigationState) {
      return null;
    }
    const route = navigationState.routes[navigationState.index];
  
    // dive into nested navigators
    if (route.routes) {
      return getActiveRouteName(route);
    }
  
    return route.routeName;
  }

export default class App extends Component<Props> {
    render() {
        
        /** * 将store传递给App框架 */
        return <Provider {...store} >
            <AppNavigator
            onNavigationStateChange={(prevState, currentState, action,navigation) => {
               
                const currentScreen = getActiveRouteName(currentState);
                const prevScreen = getActiveRouteName(prevState);
                global.routerName = currentScreen
                global.navigation = currentState.navigation
              }}
            />
        </Provider>     }
}